package com.zlc.study.controller;

import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.response.ChatResponse;
import dev.langchain4j.model.output.TokenUsage;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LowApiController {
    @Resource(name = "qwen")
    private ChatModel chatModelQwen;

    @Resource(name = "deepseek")
    private ChatModel chatModelDeepseek;

    @GetMapping(value = "/lowapi/api01")
    public String qwen(@RequestParam(value = "prompt",defaultValue = "你是谁？") String prompt){
        return chatModelQwen.chat(prompt);
    }

    @GetMapping(value = "/lowapi/api02")
    public String deepseek(@RequestParam(value = "prompt",defaultValue = "你是谁")String prompt){
        ChatResponse chatResponse = chatModelDeepseek.chat(UserMessage.from(prompt));
        TokenUsage tokenUsage = chatResponse.tokenUsage();
        System.out.println("本次调用消耗Token："+tokenUsage);
        return chatModelDeepseek.chat(prompt);
    }

}
